package cn.dankal.flyaudio.presenter;

import java.util.List;

import androidx.annotation.NonNull;
import api.ShopUserServiceFactory;
import cn.dankal.basiclib.pojo.BaseResponse;
import cn.dankal.basiclib.pojo.LogisticsEntity;
import cn.dankal.basiclib.rx.AbstractSubscriber;
import cn.dankal.flyaudio.contract.LogisticsContract;

/**
 * <pre>
 *     e-mail : junfeng.nie@duntech.com.cn
 *     time   : 23/7/2020
 *     desc   :
 *     version: cn.dankal.flyaudio.presenter
 *     Copyright: Copyright（c）2018
 *     Company:
 * </pre>
 *
 * @author niejunfeng
 */
public class LogisticsPresenter implements LogisticsContract.Presenter {
    private LogisticsContract.View mView;

    @Override
    public void shipment(String orderUuid, String type) {
        mView.showLoadingDialog();
        if(type.equals("1")) {
            ShopUserServiceFactory.shipment(orderUuid)
                    .subscribe(new AbstractSubscriber<BaseResponse<List<LogisticsEntity>>>(mView) {
                        @Override
                        public void onNext(BaseResponse<List<LogisticsEntity>> listBaseResponse) {
                            mView.dismissLoadingDialog();
                            mView.onSuccess(listBaseResponse.getData());
                        }
                    });
        }else{
            ShopUserServiceFactory.shipmentApply(orderUuid)
                    .subscribe(new AbstractSubscriber<BaseResponse<List<LogisticsEntity>>>(mView) {
                        @Override
                        public void onNext(BaseResponse<List<LogisticsEntity>> listBaseResponse) {
                            mView.dismissLoadingDialog();
                            mView.onSuccess(listBaseResponse.getData());
                        }
                    });
        }
    }

    @Override
    public void attachView(@NonNull LogisticsContract.View view) {
        this.mView = view;
    }

    @Override
    public void detachView() {
        this.mView = null;
    }
}
